package com.gvitz.transaction.activities;


import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.gvitz.transaction.R;
import com.gvitz.transaction.database.webserviceUser;
import com.gvitz.transaction.utils.validations.Field;
import com.gvitz.transaction.utils.validations.Form;
import com.gvitz.transaction.utils.validations.IsEmail;
import com.gvitz.transaction.utils.validations.NotEmpty;

public class NewRegisterActivity extends GVActivity  {

	
    private EditText mCodigo;  
    private EditText mEmail; 
    private EditText mPassword; 
    private Button mSubmit;
    private Form mForm;
    SharedPreferences prefs= null;
   

	@SuppressWarnings("unused")
	@Override
	public void onCreate(Bundle savedInstanceState) {
         
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_newregister);
        
    	
        prefs =  getSharedPreferences("preferencias", Context.MODE_PRIVATE);
        
		SharedPreferences.Editor editor = prefs.edit();	
        
        mCodigo = (EditText) findViewById(R.id.codigo_newregister);
        mEmail = (EditText) findViewById(R.id.email_newregister);
        mPassword = (EditText) findViewById(R.id.password_newregister);
        mSubmit = (Button) findViewById(R.id.submit_newregister);
        
        mForm = new Form(this);
        mForm.addField(Field.using(mCodigo).validate(NotEmpty.build(this)));
        mForm.addField(Field.using(mPassword).validate(NotEmpty.build(this)));
        mForm.addField(Field.using(mEmail).validate(NotEmpty.build(this)).validate(IsEmail.build(this)));
        
        Typeface font = Typeface.createFromAsset( getAssets(), "fonts/fontawesome-webfont.ttf" );
	      
           TextView t = (TextView) findViewById(R.id.icon_email_register);
	       TextView td = (TextView) findViewById(R.id.icon_codigo_register);
	       TextView tp = (TextView) findViewById(R.id.icon_password_register);

	       t.setTypeface(font);
	       td.setTypeface(font);
	       tp.setTypeface(font);


        
        mSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

		 		if (mForm.isValid()) {
		 					 			
		 		//Verificar codigo		        	
		 			webserviceUser w = new webserviceUser(getApplicationContext(),NewRegisterActivity.this);
		        	w.SecondRegister(mCodigo.getText().toString(),mEmail.getText().toString(),mPassword.getText().toString());         		 
            	}
            }
        });
	}
			
	}
         
   	